/* eslint-disable react-hooks/rules-of-hooks */
import React from 'react'
import { getTrainListApi } from '../../api/train'
import TrainList from './computents/TrainList'
import { NavBar } from 'antd-mobile'
import { useSearchParams } from 'react-router-dom'

function index() {
  const [sp]=useSearchParams()


  return (
    <div>
      <NavBar>{sp.get('start')}→{sp.get('end')}</NavBar>
      <TrainList/>
    </div>
  )
}

export default index

export const loader=async({request})=>{
    const url=new URL(request.url)
    const obj=Object.fromEntries(url.searchParams)
    const {data:list}=await getTrainListApi(obj)
    console.log(list);
    
    return {list}
}